package com.xiaocikuai.smallchunks.entity.User;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.time.ZoneId;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserOnline {

    private String username;
    private String device;

    private LocalDateTime lastTime;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setDevice(String device) {
        this.device = device;
    }

    public LocalDateTime getLastTime() {
        return lastTime;
    }

    public void setLastTime(LocalDateTime lastTime) {
        this.lastTime = lastTime;
    }

    public long getLastActiveTimeAsTimestamp() {
        return lastTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    }


    public UserOnline(String username, String device) {
        this.username = username;
        this.device = device;
        this.lastTime = LocalDateTime.now();
    }


    // 添加获取平台信息的方法
    public String getPlatform() {
        // 假设根据设备信息来确定平台，这里可以根据实际业务逻辑进行实现
        if (device.startsWith("app-")) {
            return "app";
        } else if (device.startsWith("mini-")) {
            return "小程序";
        } else if (device.startsWith("web-")) {
            return "网站";
        } else {
            return "未知平台";
        }
    }
}
